package com.cn.data.multipledata.api.controller;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cn.data.commont.Util.BeanCopierUtil;
import com.cn.data.commont.entity.AppUser;
import com.cn.data.commont.entity.AppUserXinDong;
import com.cn.data.multipledata.api.service.AppUserService;
import com.cn.data.multipledata.api.service.AppUserXinDongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/hahah")
public class ApiController {
    @Autowired
    AppUserService appUserService;
    @Autowired
    AppUserXinDongService appUserXinDongService;

    @GetMapping("getList")
    public List<AppUser> getList(){

        List<AppUserXinDong> list = appUserXinDongService.getList();//查询线上数据用户信息
        for (AppUserXinDong appUserXinDong : list) {
            AppUser appUser = BeanCopierUtil.copyObj(appUserXinDong, AppUser.class);
            Integer count = appUserService.get(appUser.getUserid().intValue());
            if (count==0){
                boolean save = appUserService.save(appUser);
                System.out.println(appUser.getUserid()+":数据插入情况"+save);
            }else {
                UpdateWrapper<AppUser> set = new UpdateWrapper<AppUser>().eq("userid", appUser.getUserid()).set("birthday", appUser.getBirthday());
                boolean update = appUserService.update(set);
                System.out.println(appUser.getUserid()+":修改已有数据参数"+update);
            }
        }
        return null;
    }
}
